<?php

require_once 'web.php';

/**
 * Description of HomeController
 *
 * @author user
 */
class RegisterController extends WebController {

    public function index() {

        $user = new ORM('user');
        $action = "";
        $submit_value = "Register!";
        $isi = "";

        if (isset($_POST['submit'])) {
            // Add User
            $user->set($_POST);

            $user->password = md5($user->password);
            $user->role = 'user';
            
            if($user->save()) {
                if($this->auth_user->login($user->username, $_POST['password'])) {
                    //tampilkan wallpost
                    $isi = "
                        FB.init({ appId:'155708111157721', cookie:true, status:true, xfbml:true });
                        FB.ui(
                            {
                                method: 'feed', message: 'I have just registered to Picdrops apps',
                                link: 'http://www.facebook.com/apps/application.php?id=155708111157721',
                                description : 'created by Ecky - Rezan - Andut',
                                picture: 'http://img864.imageshack.us/img864/9007/logoat.jpg'
                            },
                            function(response) {
                                if (response && response.post_id) {
                                    alert('Post was published.');
                                    window.top.location = '" . URL::site('profile/index') . "';
                                } else {
                                    alert('Post was not published.');
                                    window.top.location = '" . URL::site('profile/index') . "';
                                }
                            }
                        );
                    ";
                }
            }
        }


        $location = new ORM('location');
        $access = new ORM('access');
        
        $this->view->content = View::factory('register/index',
                array(
                    'locations'     => $location->find_all(),
                    'access'        => $access->find_all(),
                    'submit_value'  => $submit_value,
                    'action'        => $action,
                    'user'          => $user,
                    'show_username' => TRUE,
                    )
                );
        $this->view->content->updateFacebook = $isi;
    }

}

?>
